#include<iostream>
#include<cstdlib>
#include<ctime>
#include"vector.h"

int main()
{
	using namespace std;
	using VECTOR::Vector;
	srand(time(0));
	double direction;
	Vector step;
	Vector result(0.0, 0.0);
	unsigned long steps = 0;
	unsigned long largest_steps = 0;
	unsigned long lowest_steps = 0;
	unsigned long average_steps = 0;
	unsigned long all_steps = 0;
	double target;
	double dstep;
	cout << "Enter target distance (q to quit): ";
	while (cin >> target)
	{
		cout << "Enter step length: ";
		if (!(cin >> dstep))
			break;

		while (result.magval() < target)
		{
			direction = rand() % 360;
			step.reset(dstep, direction, Vector::POL);
			result = result + step;
			steps++;
		}
		if (!(largest_steps || lowest_steps))
		{
			largest_steps = steps;
			lowest_steps = steps;
		}
		if (steps > largest_steps)
			largest_steps = steps;
		else if (steps < lowest_steps)
			lowest_steps = steps;
		all_steps = all_steps + steps;
		average_steps++;
		cout << "After " << steps << " steps, the subject "
			"has the following location:\n";
		cout << result << endl;
		result.polar_mode();
		cout << " or\n" << result << endl;
		cout << "Average outward distance per step = "
			<< result.magval() / steps << endl;
		steps = 0;
		result.reset(0.0, 0.0);
		cout << "The longest steps is " << largest_steps
			<< " steps, the lowest steps is " << lowest_steps
			<< " steps, and the average steps is " << all_steps / average_steps
			<< " steps. " << endl;
		cout << "Enter target distance (q to quit): ";
	}
	cout << "Bye!\n";
	cin.clear();
	while (cin.get() != '\n')
	{
		continue;
	}
	return 0;
}